Functions
Example 4:
# functions can be passed as argument of
another functions.
def cube(x):
return x*x*x
def my_map(method, argument_list):
result = list()
for item in argument_list:
result.append(method(item))
return result
my_list = my_map(cube, [1, 2, 3, 4, 5, 6, 7, 8])
#Pass the function as argument
print(my_list)
Output:
[1, 8, 27, 64, 125, 216, 343,
512]